package com.example.about_netty.channelhandler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;


public class UnsharableMessageHandler extends SimpleChannelInboundHandler<Message> {


    //案 context 自身本就是一群属性的集合 其本身便可以维持状态 所以也可以通过handler将status维持在context中
    // 参考SharableMessageHandler
    private boolean status;

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message message) throws Exception {
        if (message instanceof SuccessMsg) status = true;
        else if (message instanceof FailedMsg) {
            status = false;
            ctx.writeAndFlush(message);
        } else {
            throw new Exception("消息数据类型错误");
        }


    }

}
